// pages/components/page_display/piccollocation/piccollocation.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    image_url: {
      type: Array,
      value:[]
    },
    maskshow: {
      type: Boolean,
      value:false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgList: [],
    upload_img: [],
    note: [],
    page: 1,
    check_mark: false,
    // downloadBtnClicked: false,
    selectedCount: 0,
    url_image: [],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onTapImage(t) {
      let dataItem = t.target.dataset.dataitem; //点击的某一项
      if (dataItem==undefined){
        return;
      }
      console.log(dataItem)
      let a = t.currentTarget.dataset.index; //数量
      console.log(a)
      let downurl = [];
      if (dataItem != undefined) {
        var y = '';
        for (let i = 0; i < this.data.image_url.length; i++) {
          if (dataItem.sub1[0].create_time == this.data.image_url[i].create_time) {
            y = i;
            break;
          }
        }
      }
      if (this.data.maskshow) {
        const selected = this.data.image_url[y].sub1[a].selected;
        this.data.image_url[y].sub1[a].selected = !selected;
        for (let i = 0; i < this.data.image_url.length; i++) {
          for (let j = 0; j < this.data.image_url[i].sub1.length; j++) {
            if (this.data.image_url[i].sub1[j].selected) {
              downurl.push(this.data.image_url[i].sub1[j].url.split('~')[0]); //点击对应需要下载的图片存在一个数组中
            }
          }
        }
      } else {
        wx.navigateTo({
          url: '../../../../page/pic_details/pic_details?item_no=' + dataItem.sub1[a].collocation,
        })
      }
      if (this.data.check_mark) { //是否在遮罩层的时候点击了图片的对勾按钮（会显示绿色对勾）是的话就让选中的图片selected变为false
        if (this.data.image_url[y].sub1 != undefined) {
          downurl = [];
          const selected = this.data.image_url[y].sub1[a].selected;
          this.data.image_url[y].sub1[a].selected = false;
          for (let i = 0; i < this.data.image_url.length; i++) {
            for (let j = 0; j < this.data.image_url[i].sub1.length; j++) {
              if (this.data.image_url[i].sub1[j].selected) {
                downurl.push(this.data.image_url[i].sub1[j].url); //点击对应需要下载的图片存在一个数组中
              }
            }
          }
        }
      }
      this.data.check_mark = false;
      this.setData({
        image_url: this.data.image_url,
      });
      let myEventDetail = {
        "downurl": downurl,
      } // detail对象，提供给事件监听函数
      this.triggerEvent('onTapImage', myEventDetail) //myevent自定义名称事件，父组件中使用
    },
    duigou() {
      this.data.check_mark = true;
    },
    //收藏
    Collection(event){
      console.log(event,"收藏")
    }
  }
})